﻿<UserControl x:Class="LFSRecord2.View.TimelineStructures.TimelineAudioLayerDataView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:lfsconv="clr-namespace:LFSRecord2.View.Converters"
             xmlns:lfsvstruct="clr-namespace:LFSRecord2.View.TimelineStructures"
             mc:Ignorable="d" 
             d:DesignHeight="18" d:DesignWidth="700" SnapsToDevicePixels="True"
             Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=Width}">
    <UserControl.Resources>
        <lfsconv:TimeOffsetToLeftMarginConverter x:Key="timeOffsetToLeftMarginConverter" />
        <lfsconv:AudioDataViewHeightConverter x:Key="audioDataViewHeightConverter" />
        <lfsconv:AudioRegionHeightConverter x:Key="audioRegionHeightConverter" />
    </UserControl.Resources>
    <Grid Background="#FFE0E0F0"
          Height="{Binding IsCollapsed, Converter={StaticResource audioDataViewHeightConverter}}"
          AllowDrop="True"
          DragEnter="UserControl_DragEnter"
          DragOver="UserControl_DragOver"
          DragLeave="UserControl_DragLeave"
          Drop="UserControl_Drop"
          MouseLeftButtonDown="Grid_MouseLeftButtonDown">
        <Line X1="0" X2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=ActualWidth}"
              Y1="0.5" Y2="0.5"
              Stroke="#70808080"
              StrokeThickness="1"
              IsHitTestVisible="False" />
        <Line X1="0" X2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=ActualWidth}"
              Y1="0.5" Y2="0.5"
              VerticalAlignment="Bottom"
              Margin="0,0,0,1"
              Stroke="#70808080"
              StrokeThickness="1"
              IsHitTestVisible="False" />
        <Line X1="0" X2="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=ActualWidth}"
              Y1="0.5" Y2="0.5"
              VerticalAlignment="Bottom"
              Stroke="#FF808080"
              StrokeThickness="1"
              IsHitTestVisible="False" />

        <Grid Name="RegionCanvas" Background="Transparent">
            <ItemsControl Name="AudioRegionsItemControl" 
                          ItemsSource="{Binding AudioRegions}" 
                          Focusable="False" 
                          Height="{Binding IsCollapsed, Converter={StaticResource audioRegionHeightConverter}}"
                          HorizontalAlignment="Left" VerticalAlignment="Top">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <lfsvstruct:AudioRegionControl
                            DataContext="{Binding}"
                            MouseLeftButtonDown="AudioRegionControl_MouseLeftButtonDown"
                            IsCollapsed="{Binding DataContext.IsCollapsed, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                            Margin="{Binding TimeOffset, Converter={StaticResource timeOffsetToLeftMarginConverter}}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>

        <Rectangle Name="DropPreviewRange" Width="100" Height="{Binding IsCollapsed, Converter={StaticResource audioRegionHeightConverter}}"
                   Margin="0, 0, 0, 1" 
                   HorizontalAlignment="Left" 
                   Fill="#80808080" Stroke="#80202020" 
                   IsHitTestVisible="False"
                   Visibility="Collapsed" />
    </Grid>
</UserControl>
